package com.wpml.ware.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wpml.common.util.PageUtils;
import com.wpml.common.util.Query;
import com.wpml.ware.dao.WareInfoDao;
import com.wpml.ware.entity.WareInfoModel;
import com.wpml.ware.service.WareInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Map;

/**
 * 仓库信息(WmsWareInfo)表服务实现类
 *
 * @author makejava
 * @since 2020-04-07 12:34:53
 */
@Service
@Slf4j
public class WareInfoServiceImpl extends ServiceImpl<WareInfoDao, WareInfoModel> implements WareInfoService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {

        QueryWrapper<WareInfoModel> wareInfoEntityQueryWrapper = new QueryWrapper<>();
        String key = (String) params.get("key");
        if (!StringUtils.isEmpty(key)) {
            wareInfoEntityQueryWrapper.eq("id", key).or()
                    .like("name", key)
                    .or().like("address", key)
                    .or().like("areacode", key);
        }

        IPage<WareInfoModel> page = this.page(
                new Query<WareInfoModel>().getPage(params),
                wareInfoEntityQueryWrapper
        );

        return new PageUtils(page);
    }
}
